"""
    __str__ 字符串方法
"""


class Student:
    name = None
    age = None

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __str__(self):
        return f"Student类对象，name = {self.name}，age = {self.age}"


stu = Student("小美", 16)
print(stu)
print(str(stu))

"""
    __lt__ 小于符号比较方法
"""


class Student1:
    name: None
    age: None

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __lt__(self, other):
        return self.age < other.age


stu1 = Student1("小美", 12)
stu2 = Student1("小帅", 18)
# print(stu1 < stu2)
# print(stu1 > stu2)

"""
    __le__ 小于等于比较符号方法
"""


class Student2:
    name: None
    age: None

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __le__(self, other):
        return self.age <= other.age


stu1 = Student2("Tom", 4)
stu2 = Student2("jay", 3)
# print(stu1 <= stu2)
# print(stu1 >= stu2)

"""
    __eq__ 比较运算符实现方法
"""


class Student3:
    name: None
    age: None

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __eq__(self, other):
        return self.age == other.age


stu1 = Student3("小明", 14)
stu2 = Student3("小花", 14)
print(stu1 == stu2)
